#include "vtor_string_player.h"

// 修改成用户的工程宏
#ifdef __DEMO_PROJECT__
// 加入用户用中需要用到的头文件
#include "main.h"
#include "tim.h"
#include "vtor_elec_module.h"


// 实例化一个蜂鸣器音乐播放器

VtorStringPlayer vtorStringPlayer[2];
VtorStringPlayer* beepPlayer;
VtorStringPlayer* beepRecordPlayer;
char recordPushIdx = 0;
char recordString[512] = {0};

void Beep_SetFreq(int freq)
{
	static int oldFreq = 0;
	if(oldFreq == freq)
	{
		return ;
	}
	if(0 == freq)
	{
		HAL_TIM_Base_Stop(&htim2);
	}
	else
	{
		/*
		arr值1 1us中断 1mhz中断 500khz音调
		arr值2 2us中断 500khz中断 250khz音调
		音调 = 1000000/2/arr
		*/
		htim2.Instance->ARR = 1000000 / 2 / freq;
		if(htim2.State == HAL_TIM_STATE_READY)
		{
			HAL_TIM_Base_Start_IT(&htim2);
		}
	}

	oldFreq = freq;
}

uint8_t xiaoxingxing[]={

	// 小星星
	"10.10.50.50.60.60.50"
	"40.40.30.30.20.20.10"
	"50.50.40.40.30.30.20"
	"50.50.40.40.30.30.20"
	"10.10.50.50.60.60.50"
	"40.40.30.30.20.20.10==",
};
uint8_t yujian[]={

	// 孙燕姿-遇见
	"567;+1;0,7+17656;:0.5;0"
	"1234:.0,345123:0..3;:0"
	"567+1:0,7+1+2+1+2+3;:5;0"
	"1234:0,343221-71;0==",
};

int8_t* stringMusicArray[] = {
	xiaoxingxing,
	yujian,
	NULL
};


int16_t recordMusicBufIdx = 0;
uint8_t recordMusicBuf[500] = {"0"};

const uint8_t* recordMusicArray[] = {
	recordMusicBuf,
	NULL
};

void VtorStringPlayer_Init()
{
	beepPlayer = &vtorStringPlayer[0];
	beepRecordPlayer = &vtorStringPlayer[1];

	VtorStringPlayer* player = beepPlayer;
	player->list = stringMusicArray;
	player->music = player->list;
	player->charactor = *player->music;
	player->presetToneLen = 50;

	player = beepRecordPlayer;
	player->list = recordMusicArray;
	player->music = player->list;
	player->charactor = *player->music;
	player->presetToneLen = 50;
}

// 切换歌曲的回调函数
void VtorStringPlayer_PlayFreq(VtorStringPlayer* player)
{
	if(player == beepPlayer)
	{
		Beep_SetFreq(player->freq);
	}
	if(player == beepRecordPlayer)
	{
		Beep_SetFreq(player->freq);
	}
}

void VtorStringPlayer_SwitchMusicCallback(VtorStringPlayer* player)
{
//	printf("music %s\r\n",*player->music[0]);
/*
	if(*player->music == stringMusic_HuYanBing_YueGuang)
	{
		//player->presetToneLen = 4;
	}
*/
}

#endif

